"""
Template Item 模板项表模型
"""
import uuid
from sqlalchemy import Column, Text, Enum, Integer, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from db.base import Base

class TemplateItem(Base):
    """模板项数据模型"""
    __tablename__ = "template_item"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    template_id = Column(
        UUID(as_uuid=True), 
        ForeignKey("compliance_template.id", ondelete="CASCADE"), 
        nullable=False, 
        comment="关联的模板ID"
    )
    title = Column(Text, nullable=False, comment="标题")
    description = Column(Text, nullable=True, comment="描述")
    guide = Column(Text, nullable=True, comment="指导说明")
    compliance_type = Column(
        Enum('risk', 'guarantee', name='compliance_type'), 
        nullable=False, 
        comment="合规类型（风险/保障）"
    )
    maturity_level = Column(Integer, nullable=True, default=1, comment="成熟度等级")

    # 关系
    template = relationship("ComplianceTemplate", back_populates="template_items")
    document_compliance_relations = relationship("DocumentComplianceRelation", back_populates="compliance_template_item")
